package android.textIt.frontend.adapter;

import java.util.List;

import android.content.Context;
import android.textIt.R;
import android.textIt.backend.model.User;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ContactListAdapter extends ArrayAdapter<User> {
	 private Context context;
	 private List<User> items;

   public ContactListAdapter(Context context, List<User> contacts) {
           super(context, R.layout.li_contacts, contacts);
           this.context = context;
           this.items = contacts;
   }

   @Override
   public View getView(int position, View convertView, ViewGroup parent) {
       if (convertView == null) {
           LayoutInflater vi = 
          	 (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
           convertView = vi.inflate(R.layout.li_contacts, null);
       }
       User user = items.get(position);
       TextView tvContact = (TextView) convertView.findViewById(R.id.TxtContactName);
       tvContact.setText(user.getName());

       TextView tvPhone = (TextView) convertView.findViewById(R.id.TxtContactIsTextItUser);
       tvPhone.setText(user.isTextItUser()?"TextIt":"Mobile");

       TextView tvId = (TextView) convertView.findViewById(R.id.TxtContactId);
       tvId.setText(Long.toString(user.getId()));

       
       TextView tvgroupId = (TextView) convertView.findViewById(R.id.TxtContactIGroupId);
       tvgroupId.setText(Long.toString(user.getiGroup()));
       return convertView;
   }
}
